<?php
/*
 * @Description    : 喵付通异步通知
 * @Version        : 1.0.0
 * @Author         : QianLong
 * @Date           : 2022-03-16 14:50:04
 * @LastEditors    : QianLong
 * @LastEditTime   : 2024-11-20 15:43:38
 * @HomeUrl        : https://www.ecmpay.cn
 */

namespace app\api\controller;

use Ecmpay\Ecmpay\Ecmpay;
use think\Controller;

class EcmpayNotify extends Controller
{
  /**
   * 支付成功异步通知
   * @param $data
   * @return mixed
   */
  public function order()
  {
    if (request()->isPost()) {
      $get_info = input('param.');
      if (!empty($get_info)) {
        $log_id = $get_info['trade_no'];
        $log_arr = explode('_', $log_id);
        $order_info = Db::name('demo_order')->where('order_no', $log_arr[0])->find();
        if (empty($order_info)) {
          throw new \Exception('无此订单');
        }
        Ecmpay::init(['app_id'=>'xxxx','auth_app_id'=>'xxx','appSecret'=>'xxxx']);
        if (!Ecmpay::signVerify($get_info)) {
          throw new \Exception('签名校验失败');
        }
        $trade_status = $get_info['event'];
        if ($trade_status == 'PAYMENT_SUCCESS') {
          // 这里为支付成功后的操作
        }
        echo "success";
      } else {
        echo "empty";
      }
    }
  }
}
